﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nonocast.Scheduling {
	[Flags]
	public enum Days {
		None = 0x00000000,
		Monday = 0x00000001,
		Tuesday = 0x00000010,
		Wednesday = 0x00000100,
		Thursday = 0x00001000,
		Friday = 0x00010000,
		Saturday = 0x00100000,
		Sunday = 0x01000000,
		Workdays = 0x00011111,
		All = 0x01111111,
	}

	public class WeekMask {
		public WeekMask(params Days[] args) {
			days = Days.None;
			foreach (Days each in args) {
				days |= each;
			}
		}

		public bool Contains(Days arg) {
			return days.HasFlag(arg);
		}

		public bool Contains(DayOfWeek arg) {
			return Contains(daysMapping[arg]);
		}

		public override string ToString() {
			return days.ToString();
		}

		public WeekMask Append(Days arg) {
			this.days |= arg;
			return this;
		}

		static WeekMask() {
			daysMapping = new Dictionary<DayOfWeek, Days> {
				{DayOfWeek.Monday, Days.Monday},
				{DayOfWeek.Tuesday, Days.Tuesday},
				{DayOfWeek.Wednesday, Days.Wednesday},
				{DayOfWeek.Thursday, Days.Thursday},
				{DayOfWeek.Friday, Days.Friday},
				{DayOfWeek.Saturday, Days.Saturday},
				{DayOfWeek.Sunday, Days.Sunday}
			};
		}

		public Days days { get; private set; }
		private static Dictionary<DayOfWeek, Days> daysMapping;
	}
}
